package cn.zhuama.common.controller;

import cn.zhuama.basic.util.AjaxResult;
import cn.zhuama.org.domain.Logininfo;
import cn.zhuama.org.mapper.LogininfoMapper;
import cn.zhuama.org.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("refresh")
public class RefreshController {
    @Autowired
    ILogininfoService iLogininfoService;
    //在这里重新生成新token 发送给前端
    @PostMapping
    public AjaxResult refresh(@RequestBody Logininfo logininfo){
        try {
            Map<String,Object> mapl = iLogininfoService.newToken(logininfo);
            //刷新成功 返回token 保存到前端localstorge
            return AjaxResult.me().setObject(mapl);
        } catch (Exception e) {
            e.printStackTrace();
            //刷新失败 返回失败 保存到前端localstorge
            return AjaxResult.me().setSuccess(false).setMessage("刷新失败");
        }
    }

}
